﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;

namespace TestRestSharp
{

    public class ShareDoveSessions
    {
        public const string DeliciousFeedBase = @"http://sharedove.cld.sr/sahreconf2012/_vti_bin/ShareDoveRestService/ShareDove.svc/anonymous/GetSessions";
        
        private RestSharp.RestClient _client;
        
        public ShareDoveSessions()
        {
            this._client = new RestClient
            {
                BaseUrl = DeliciousFeedBase
            };
        }

        public Sessions GetSessions()
        {
            var request = new RestRequest { RequestFormat = DataFormat.Xml};
            var response = this._client.Execute<Sessions>(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                System.Runtime.Serialization.Json.DataContractJsonSerializer deserializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Sessions));

                Sessions sessions = deserializer.ReadObject(new System.IO.MemoryStream(response.RawBytes)) as Sessions;

                return sessions;

            }
            else
            {
                throw new Exception("Could not deserialize sessions");
            }

            
        }
    }


    public class Sessions
    {
        public Sessions()
        {
        }

        public Session[] AllSessions { get; set; }
    }


    public class Session
    {
        public Session()
        {
        }

        public int ID { get; set; }
        public string Abstract { get; set; }
        public int Duration { get; set; }
        public DateTime EndTime { get; set; }
        public int RoomId { get; set; }
        public string RoomName { get; set; }
        public DateTime Slot { get; set; }
        public string SpeakerAddressLatitude { get; set; }
        public string SpeakerAddressLongitude { get; set; }
        public string SpeakerCity { get; set; }
        public string SpeakerName { get; set; }
        public string Title { get; set; }
        public int TrackId { get; set; }
        public string TrackName { get; set; }
    }
    


}